package com.tongjie.hotelbooking.user.entity;

import com.tongjie.hotelbooking.role.entity.Role;
import com.tongjie.hotelbooking.user.enums.UserStatus;
import com.tongjie.hotelbooking.user.enums.UserType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "hb_user")
public class User implements Serializable {

    private static final long serialVersionUID = 1116637174001769843L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column
    private String username;

    @Column
    private String password;

    @Column
    private String nickName;

    @Column
    private String avatar;

    @Enumerated(EnumType.STRING)
    @Column(length = 20, nullable = false)
    private UserType userType;

    @Enumerated(EnumType.STRING)
    @Column(length = 20, nullable = false)
    private UserStatus userStatus;

    @Column(unique = true)
    private String mobile;

    @Column(nullable = false, unique = true)
    private String uuid;

    @Column(nullable = false, unique = true)
    private String wxOpenId;

    @Column
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date registerTime;

    @Column
    private String registerIp;

    @Column
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date lastLoginTime;

    @Column
    private String lastLoginIp;

    @Column
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date createTime;

    @Column
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date lastUpdateTime;

    @ManyToMany(cascade = {CascadeType.ALL})
    @JoinTable(name = "hb_user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
    private List<Role> roles = new ArrayList<>();

}
